<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="图纸ID" prop="drawingId">
        <el-select v-model="queryParams.drawingId" placeholder="请选择图纸" clearable>
          <el-option
            v-for="drawing in drawingList"
            :key="drawing.id"
            :label="drawing.name"
            :value="drawing.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="开关名称" prop="switchName">
        <el-input
          v-model="queryParams.switchName"
          placeholder="请输入开关名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.biz_catenary_switch_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:catenary_switch:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:catenary_switch:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:catenary_switch:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:catenary_switch:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="catenary_switchList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="部门id" align="center" prop="deptId" />
      <el-table-column label="图纸ID" align="center" prop="drawingId" />
      <el-table-column label="开关名称" align="center" prop="switchName" />
      <el-table-column label="描述信息" align="center" prop="description" />
      <el-table-column label="标准参数" align="center" prop="standardParams" />
      <el-table-column label="自定义参数" align="center" prop="customParams" />
      <el-table-column label="打开时颜色" align="center" prop="openColor" />
      <el-table-column label="打开时扩展样式" align="center" prop="openStyleExt" />
      <el-table-column label="关闭时颜色" align="center" prop="closeColor" />
      <el-table-column label="关闭时扩展样式" align="center" prop="closeStyleExt" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.biz_catenary_switch_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="该开关对应线路通用样式" align="center" prop="lineCommonStyle" />
      <el-table-column label="基础信息" align="center" prop="basicInfo" />
      <el-table-column label="扩展信息" align="center" prop="ext" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:catenary_switch:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:catenary_switch:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改接触网开关数据管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="图纸ID" prop="drawingId">
          <el-select v-model="form.drawingId" placeholder="请选择图纸" clearable>
            <el-option
              v-for="drawing in drawingList"
              :key="drawing.id"
              :label="drawing.name"
              :value="drawing.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="开关名称" prop="switchName">
          <el-input v-model="form.switchName" placeholder="请输入开关名称" />
        </el-form-item>
        <el-form-item label="描述信息" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="标准参数" prop="standardParams">
          <el-input v-model="form.standardParams" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="自定义参数" prop="customParams">
          <el-input v-model="form.customParams" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="打开时颜色" prop="openColor">
          <el-input v-model="form.openColor" placeholder="请输入打开时颜色" />
        </el-form-item>
        <el-form-item label="打开时扩展样式" prop="openStyleExt">
          <el-input v-model="form.openStyleExt" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="关闭时颜色" prop="closeColor">
          <el-input v-model="form.closeColor" placeholder="请输入关闭时颜色" />
        </el-form-item>
        <el-form-item label="关闭时扩展样式" prop="closeStyleExt">
          <el-input v-model="form.closeStyleExt" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.biz_catenary_switch_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="该开关对应线路通用样式" prop="lineCommonStyle">
          <el-input v-model="form.lineCommonStyle" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="基础信息" prop="basicInfo">
          <el-input v-model="form.basicInfo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="扩展信息" prop="ext">
          <el-input v-model="form.ext" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCatenary_switch, getCatenary_switch, delCatenary_switch, addCatenary_switch, updateCatenary_switch } from "@/api/system/catenary_switch"
import { getStation_drawingByUser } from "@/api/system/station_drawing"
export default {
  name: "Catenary_switch",
  dicts: ['biz_catenary_switch_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 接触网开关数据管理表格数据
      catenary_switchList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        drawingId: null,
        switchName: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createBy: [
          { required: true, message: "创建者不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateBy: [
          { required: true, message: "更新者不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" }
        ],
        drawingId: [
          { required: true, message: "图纸ID不能为空", trigger: "blur" }
        ],
        switchName: [
          { required: true, message: "开关名称不能为空", trigger: "blur" }
        ],
        openColor: [
          { required: true, message: "打开时颜色不能为空", trigger: "blur" }
        ],
        closeColor: [
          { required: true, message: "关闭时颜色不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ],
      },
      drawingList:[]
    }
  },
  created() {
    this.initData()
    this.getList()
  },
  methods: {
    initData(){
      getStation_drawingByUser().then(response => {
        this.drawingList = response.data;
      })
    },
    /** 查询接触网开关数据管理列表 */
    getList() {
      this.loading = true
      listCatenary_switch(this.queryParams).then(response => {
        this.catenary_switchList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        deptId: null,
        drawingId: null,
        switchName: null,
        description: null,
        standardParams: null,
        customParams: null,
        openColor: null,
        openStyleExt: null,
        closeColor: null,
        closeStyleExt: null,
        status: null,
        lineCommonStyle: null,
        basicInfo: null,
        ext: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加接触网开关数据管理"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getCatenary_switch(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改接触网开关数据管理"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCatenary_switch(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addCatenary_switch(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除接触网开关数据管理编号为"' + ids + '"的数据项？').then(function() {
        return delCatenary_switch(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/catenary_switch/export', {
        ...this.queryParams
      }, `catenary_switch_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
